import 'package:eh_mobile/common/utils/extension.dart';
import 'package:eh_mobile/common/values/svg_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';

import 'index.dart';

class SetupPage extends GetView<SetupController> {
  const SetupPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return SingleChildScrollView(
        child: Padding(
      padding: const EdgeInsets.all(14),
      child: Column(
        children: [
          _buildListView(0),
          20.sizedBoxHeight,
          _buildListView(1),
          20.sizedBoxHeight,
          _buildListView(2),
        ],
      ),
    ));
  }

  Widget _buildListView(int section) {
    return Container(
      decoration: const BoxDecoration(
        color: Color(0xfff2f3f5),
        borderRadius: BorderRadius.all(Radius.circular(8)),
      ),
      height: 54.0 * controller.listTitles[section].length,
      child: ListView.builder(
        itemBuilder: (context, index) {
          return _buildListViewItem(context, index, section);
        },
        itemExtent: 54,
        physics: const NeverScrollableScrollPhysics(),
        itemCount: controller.listTitles[section].length,
      ),
    );
  }

  Widget _buildListViewItem(BuildContext context, int index, int section) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(
          height: 53,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              10.sizedBoxWidth,
              SvgPicture.asset(SVGImage.dynamicIcDnwSvg),
              10.sizedBoxWidth,
              Expanded(
                  child: Text(
                controller.listTitles[section][index],
                style: const TextStyle(fontSize: 16, color: Color(0xff303133)),
              )),
              const Icon(Icons.keyboard_arrow_right),
              10.sizedBoxWidth,
            ],
          ).onClick(() {
            controller.listViewItemClick(section, index);
          }),
        ),
        Container(
          margin: const EdgeInsets.fromLTRB(14, 0, 14, 0),
          color: const Color.fromARGB(255, 190, 185, 185),
          height: (index < controller.listTitles.length - 1) ? 1 : 0,
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SetupController>(
      init: SetupController(),
      id: "setup",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
              title: const Text('设置'),
              automaticallyImplyLeading: false, //隐藏返回按钮
              actions: [
                IconButton(
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    icon: const Icon(Icons.close))
              ]),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
